import http from "@/utils/request";
import type { CoursePlan, CoursePlanForm, CoursePlanQueryParams } from "./types";

/**
 * 获取分页列表
 *
 * @param queryParams
 */
export const getCoursePlanPage = (queryParams: CoursePlanQueryParams) => {
  return http({
    url: "/api/v1/course-plan/page",
    method: "get",
    params: queryParams,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 获取表单详情
 *
 * @param id
 */
export const getCoursePlanForm = (id: number) =>{
  return http({
    url: "/api/v1/course-plan/getCoursePlanForm",
    method: "get",
    params: {id: id},
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 添加
 *
 * @param data
 */
export const addCoursePlan = (data: CoursePlan) => {
  return http({
    url: "/api/v1/course-plan/add",
    method: "post",
    data: data,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 修改信息
 *
 * @param data
 */
export const updateCoursePlan = (data: CoursePlanForm) => {
  return http({
    url: "/api/v1/course-plan/update",
    method: "put",
    data: data,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 删除信息
 * @param id
 */
export const deleteCoursePlan = (id: number) => {
  return http({
    url: "/api/v1/course-plan/delete",
    method: "delete",
    data: id,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

export const getPlansByCourseId = (id: number) => {
  return http({
    url: "/api/v1/course-plan/getPlansByCourseId",
    method: "get",
    params: {id: id},
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const batchAddCoursePlan = (plans: CoursePlan[]) => {
  return http({
    url: "/api/v1/course-plan/batchAdd",
    method: "post",
    data: plans,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

export const clearCoursePlans = (id: number) => {
  return http({
    url: "/api/v1/course-plan/clearPlans",
    method: "delete",
    data: id,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
